package com.kaifamiao.contraller;

import com.kaifamiao.model.OrderModel;
import com.kaifamiao.service.OrderService;
import com.kaifamiao.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderContraller {

    @Autowired
    private OrderService service;

    @RequestMapping("/findOrder")
    @CrossOrigin("*")
    public ResponseUtil selectById(@RequestParam(value = "id",required = false) Integer id){

        OrderModel model = service.selectById(id);
        System.out.println(model);
        if(model != null){
            return ResponseUtil.ok("查询成功",model);
        }else{
            return ResponseUtil.error("查询失败");
        }
    }

    @RequestMapping("/addOrder")
    public int addOrder(){
        return service.insertOrder(3,"02",1);
    }


    //查询一个教室里所有被选的座位
    @RequestMapping("/allSelected")
    @CrossOrigin("*")
    public ResponseUtil allSelectedSeats(@RequestParam(value = "fno",required = false) Integer fno,
                                   @RequestParam(value = "rno",required = false) String rno){
        List<OrderModel> seats = service.allSelectedSeats(fno,rno);

        int k = seats.size();
        if(k >= 0){
            return ResponseUtil.ok("被选中座位查询成功",seats);
        }else{
            return ResponseUtil.error("被选中座位查询失败");
        }
    }
}
